import Ember from 'ember';
import BaseBusiness from '../base-business';
import Pagination from '../pagination';

export default BaseBusiness.extend(Pagination,{
  header_title:'护理排班列表',
  model() {
    return {};
  },
  buildQueryParams:function(){
    var params=this.pagiParamsSet();
    var curController = this.getCurrentController();
    var filter={};
    var sort;
    if (curController) {
        if (curController.get('queryCondition')) {
          filter = $.extend({}, filter, {'[user][name@$like]@$or1':curController.get('queryCondition')});
          // filter = $.extend({}, filter, {'[user][bed][name@$like]@$or1':curController.get('queryCondition')});
        }
    }
    if(this.get('typeID')){
      filter = $.extend({}, filter, {'[type][id]':this.get('typeID')});
    }
    params.filter = filter;
    sort = {
        remark: 'asc'
    };
    params.sort = sort;
    return params;
  },
  doQuery:function(){
    // var _self=this;
    var params=this.buildQueryParams();
    console.log("params is",params);
    // var staffscheduleList=this.findPaged('staffschedule',params).then(function(staffscheduleList){
    //   _self.getCurrentController().set("staffscheduleList", staffscheduleList);
    // });
    // _self.getCurrentController().set("typeID",'');
    var staffscheduleList=this.findPaged('staffschedule',params,function(staffscheduleList){});
    this.getCurrentController().set("staffscheduleList", staffscheduleList);
    this.getCurrentController().set("typeID",'');
  },
  actions:{
    search:function(){
      this.doQuery();
    },
    typeSelect(type){
      if(type){
        this.set('typeID',type.id);
      }else{
        this.set('typeID','');
      }
      this.doQuery();
    }
  },
  setupController: function(controller,model){
    this.set('typeID','');
    var _self=this;
    this.doQuery();
    var userList=this.store.query('user',{}).then(function(userList){
      userList.forEach(function(user){
        user.set('namePinyin',pinyinUtil.getFirstLetter(user.get("name")));
      });
      _self.getCurrentController().set('userList',userList);
    });
    var queryCondition = controller.get('input');
    controller.set('queryCondition', queryCondition);
    this._super(controller,model);
  }
});
